/*********************************************************************
 *                                                                   *
 *  Js Css Minifier ( JsCssMin )                                     *
 *  Author: Igor Kanshyn                                             *
 *  Copyright (c) 2009, Igor Kanshyn. All rights reserved.           *
 *                                                                   *
 *  JsCssMin is released under the Apache Software License.          *
 *  See LICENSE.txt for more details.                                *
 *                                                                   *
 *********************************************************************/

package org.grenader.jscssmin;

import org.grenader.jscssmin.model.Resource;
import org.grenader.jscssmin.model.ResourceGroup;

import java.io.File;

/**
 * <p>Product: JsCssMin ( JavaScript and CSS Minifier )<br>
 * Author: Igor Kanshyn (grenader).
 * </p>
 * Date: May 1, 2009
 */
abstract public class JsCssProcessor {
    private JsCssMinConfig config;

    protected JsCssProcessor() {
        config = new JsCssMinConfig();
    }

    protected JsCssProcessor(JsCssMinConfig config) {
        if (config == null)
            throw new IllegalArgumentException("JsCssMinProcessor has not been created. jcssMinConfig can't be null.");

        this.config = config;
    }

    public abstract void startGroup(ResourceGroup resourceGroup);

    /**
     * @param resource resouce object to process
     * @return return true if everything was Ok (file was found,processed and copied) successfully, otherwise return false.
     */
    abstract boolean processResource(Resource resource);

    public abstract void processGroupsResource(Resource resource);

    public abstract void commitGroup(ResourceGroup resourceGroup);

    abstract String readFileContent(File file);

    abstract void writeResultsIntoFile(File file, String content);

    public JsCssMinConfig getConfig() {
        return config;
    }

    public abstract void finishProcessing();
}
